#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# author: maxiao
# date: 2023-03-14 11:22
# description: 通过python连接mysql数据库，查询数据

import numpy as np
import pandas as pd
from sqlalchemy import create_engine

# username为数据库用户名 password为用户登陆的密码
engine = create_engine("mysql+pymysql://username:password@localhost:3306/test", encoding="utf8")
# 从数据库中查询数据，并将结果保留在df中
#sql = "select * from list order by id desc limit 15"
#df = pd.read_sql(sql, engine)

# 从xlsx文件中读取数据，写入到数据库
df = pd.read_excel('poem.xlsx')
df.to_sql("poem", engine, if_exists='append', index=False)

